package nsu.grandfinal;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class AlertPopup extends Activity {
	LinearLayout					popup_Linear;
	private int						mode;
	private String				sound;
	private AudioManager	aManager;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.popup);
		Intent intent = new Intent();
		mode = intent.getIntExtra("mode", 1);
		sound = "";
		switch (mode) {
			case 1:
				sound = "벨소리";
				break;
			case 2:
				sound = "진동";
				break;
			case 3:
				sound = "무음";
				break;
		}
		aManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
		popup_Linear = (LinearLayout) findViewById(R.id.AlertPopup);
		popup_Linear.setBackgroundColor(Color.rgb(125, 125, 125));
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
		TextView tv = (TextView) findViewById(R.id.message);
		tv.setText("위치검색에 실패하였습니다");
		Button confirm_button = (Button) findViewById(R.id.btn_confirm);
		Button cancle_button = (Button) findViewById(R.id.btn_cancle);
		confirm_button.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				switch (mode) {
					case 1:
						aManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
						break;
					case 2:
						aManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
						break;
					
					case 3:
						aManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
						break;
				}
				Toast.makeText(AlertPopup.this, sound + "모드로 변경", Toast.LENGTH_LONG).show();
				finish();
			}
		});
		cancle_button.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Toast.makeText(AlertPopup.this, "설정을 변경하지 않습니다", Toast.LENGTH_LONG).show();
				finish();
			}
		});
	}
	
	protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
		super.onApplyThemeResource(theme, resid, first);
		theme.applyStyle(android.R.style.Theme_Panel, true);
	}
}
